<template>
    <div class="user_message">

        <div style="width: 660px;height: 60px">
            <ul>
                <li style="margin-left: 75px;cursor: pointer"><span @click="dfh()">待发货</span></li>

                <li style="margin-left: 75px;cursor: pointer"><span @click="dsh()">待收货</span></li>
                <li style="margin-left: 75px;cursor: pointer"><span @click="yqr()">已确认收货</span></li>
            </ul>
        </div>

        <el-table :data="tableData" style="width: 100%">
            <el-table-column prop="name" label="收货人" width="180" />
            <el-table-column prop="telephone" label="电话号" width="180" />
            <el-table-column prop="address" label="地址" width="180"/>
            <el-table-column prop="date" label="日期" width="180" />
            <el-table-column label="操作">
                <template #default="scope">
                    <el-button  v-show="fhShow"
                        size="small"
                        type="success"
                        @click="fh(scope.row.id)"
                    >发货</el-button>
                    <el-button  v-show="xqShow"
                        size="small"
                        type="success"
                        @click="xq(scope.row.id)"
                    >详情</el-button>
                </template>
            </el-table-column>
        </el-table>
    </div>

    <el-dialog v-model="orderD" title="订单详情" width="380px" style="text-align: center;">
        <el-form :model="order">
            <el-form v-for="(item, index) in order.orderItems" :key="item.id">
                <el-form-item>
                    <el-image style="height: 100px;width: 100px;margin-left: 120px"
                              :src="`http://127.0.0.1:8081/product/${item.product.picture}`"/>
                </el-form-item>
                <el-form-item label="商品名称：">
                    {{item.product.title}}
                </el-form-item>
                <el-form-item label="收货人：">
                    {{order.address.name}}
                </el-form-item>
                <el-form-item label="收货地址：">
                    {{order.address.address}}
                </el-form-item>
                <el-form-item label="联系方式：">
                    {{order.address.telephone}}
                </el-form-item>
                <hr>
            </el-form>
        </el-form>
    </el-dialog>
</template>

<script setup>
import {onMounted, ref, reactive, toRaw} from 'vue'
import {ElMessageBox, ElTable} from 'element-plus'
import goodApi from '../../api/goods.js'
import axios from 'axios'
import router from '../../router/index.js'
import {ElMessage} from "element-plus";
import orderApi from "../../api/order.js"
const fhForm = reactive({
    sta: 1
})
const dshForm = reactive({
    sta: 2
})
const qrshForm = reactive({
    sta: 4
})

const tableData = ref([])
const fhShow = ref(false)
onMounted(()=>{
    orderShow()
})
const orderForm = reactive({
    id:''
})
const orderShow = async() =>{
    const res = await orderApi.queryBySidAndSta(fhForm)
    tableData.value = res.data
    fhShow.value = true
}
const dfh = () => {
    orderShow()
}
const fh = async(id) =>{
    orderForm.id = id
    const res = await orderApi.modifySta2(orderForm)
    if(res.data){
        console.log("11111")
    }
}

const xqShow = ref(false)
const dsh = async() =>{
    const res = await orderApi.queryBySidAndSta(dshForm)
    console.log(res.data)
    tableData.value = res.data
    fhShow.value = false
    xqShow.value = true
}

const yqr = async() =>{
    const res = await orderApi.queryBySidAndSta(qrshForm)
    tableData.value = res.data
    fhShow.value = false
    xqShow.value = true
}
const orderD = ref(false)
const order = ref([])
const xq = async(id) =>{
    orderD.value = true
    orderForm.id = id
    const res = await orderApi.queryById(orderForm)
    order.value = res.data
}


</script>

<style>
.user_message {
    margin: 20px 0px 0px 10px;
}

.user_message .el-table {
    margin-top: 10px;
}

.block {
    margin-top: 10px;
}
ul{
    list-style: none;
}
ul li{
    float: left;
    font-size: 13px;
}
</style>